~function (pro) {
    //->format:解析一个URL地址问号传递参数的值
    function format() {
        var reg = /([^?=&#]+)=([^?=&#]+)/g,
            obj = {};
        this.replace(reg, function () {
            obj[arguments[1]] = arguments[2];
        });
        return obj;
    }

    pro.format = format;
}(String.prototype);
var $imgUpload = $('#J_imgupload');

require(['init'], function () {
    //初始数据
    var $J_teacheradd_wrap = $('#J_teacheradd_wrap').html('');
    $(' <div class="formLi">\
            <div class="formTitle">\
            <span> ClassIn账号：</span>\
    </div>\
        <div class="formContent">\
            <span id="zh">12315613215</span>\
            <input type="hidden" name="zh">\
        </div>\
    </div>\
        <div class="formLi">\
            <div class="formTitle">\
                <span>姓         　 　名：</span>\
                </div>\
                <div class="formContent">\
                <span id="J_name"></span>\
                </div>\
                </div>\
                <div class="formLi">\
                <div class="formTitle">\
                <span>性        　  　别：</span>\
                </div>\
                <div class="formContent">\
                <span id="sex">男</span>\
                <input type="hidden" name="gender">\
                </div>\
                </div>\
                <div class="formLi">\
                <div class="formTitle">\
                <span>电        　  　话：</span>\
                </div>\
                <div class="formContent">\
                <span id="phone"></span>\
                <input type="hidden" name="iphone">\
                </div>\
                </div>\
                <div class="formLi">\
                <div class="formTitle">\
                <span>课         　 　程：</span>\
                </div>\
               <div class="formContent">\
                    <div id="J_coursetypes"></div>\
                    <div class="J_coursetype_help"></div>\
                </div>\
            </div>\
            <div class="formLi">\
            <div class="formTitle">\
             <span>头         　 　像：</span>\
            </div>\
            <div class="formContent" id="J_imgupload">\
            <span class="icon ">\
            <img width="200" height="200" id="J_img" style="display: none">\
            <input type="file" name="Filedata" multiple="multiple" data-url="/api/file/upload"style="display: none">\
            </span>\
            </div>\
            </div>\
            <div class="formLi">\
            <div class="formTitle">\
             <span>邮         　 　箱：</span>\
            </div>\
            <div class="formContent">\
            <span id="email">无</span>\
            <input type="hidden" name="email">\
            </div>\
            </div>\
            <div class="formLi">\
            <div class="formTitle">\
             <span>简         　 　介：</span>\
            </div>\
            <div class="formContent">\
            <div id="introduce">无</div>\
            </div>\
            </div>\
            <div class="formLi">\
            <div class="formTitle">\
             <span>备         　 　注：</span>\
            </div>\
            <div class="formContent">\
            <span id="J_remark1">无</span>\
            <input type="hidden" name="teach_student_count">\
            </div>\
            </div>\
            <div class="formLi">\
            <div class="formTitle">\
             <span>备         　 　注：</span>\
            </div>\
            <div class="formContent">\
            <span id="J_remark2">无</span>\
            <input type="hidden" name="teach_student_count">\
            </div>\
            </div>\
            <div class="formLi">\
            <div class="formTitle">\
             <span>背         　 　景：</span>\
            </div>\
            <div class="formContent">\
            <span></span>\
            <div id="J_eduction2">\
            <ul id="ul">\
            </ul>\
            </div>\
            </div>\
            </div>\
            <div class="formLi">\
            <div class="formTitle">\
             <span>经         　 　历：</span>\
            </div>\
            <div class="formContent">\
            <span></span>\
            <div id="J_workexp2">\
            <ul id="J_workexp3">\
            </ul>\
            </div>\
            </div>\
            </div>').appendTo($J_teacheradd_wrap);
    //公司的初始密码
    var needPw = true;
    var $name = $('[name=name]');
    var $tuid = $('[name=tuid]');
    var $genderWrap = $('.genderWrap');
    var $courseType = $('#J_coursetypes');
    var $phone = $('[name=phone]');
    var $classInNo = $('[name=classin_no]');
    var $photo = $('#J_img');
    var $resume = $('#J_resume_filename');
    var $email = $('[name=email]');
    var $introduce = $('[name=introduce]');
    var $studentMax = $('[name="teach_student_count"]');
    var $lessontime = $('[name="lessontime_text"]');
    var $submitBtn = $('#J_teacheradd');
    var $imgUpload = $('#J_imgupload');
    var $resumeUpload = $('#J_resume');
    var $education = $('#J_eduction');
    var $workExp = $('#J_workexp');
    var tuid = location.search.urlToObj().tuid;


    var $redact = $('#redact');
    var $gender = $('[name=gender]');
    var $age = $('[name=age]');
    var $day = $('[name=day]');
    var $zh = $('[name=zh]');
    var $subject = $('[name=subject]');
    var doctorId;
    var teacheruid;

    function bind(data) {
        var cur = data.data;
        $('#J_name').text(cur.lastname);
        cur.sex == '0' ? $('#sex').text(i18next.t('sex.man')) : $('#sex').text(i18next.t('sex.woman'));
        var ary = [];
        ajaxMethod({
            url: '/api/coursetypes',
            success: function (data) {
                $.each(data, function (i, item) {
                    ary.push(item.coursetypename)
                });
                $.each(cur.coursedesc, function (index, item) {
                    var a = $('<span style="padding-right: 5px">' + ary[item - 1] + '</span>').appendTo($('#J_coursetypes'));
                    console.log(ary[item - 1]);
                    // $('#J_coursetypes').append(a)
                });
            }
        });
        var reg = /(\d+)-(\d+)-(\d+)\s\d+:\d+:\d+/;
        $.each(cur.educations, function (i, item) {
            begindate = item.begindate.replace(reg, function ($1, $2, $3) {
                return $2 + "年" + $3 + "月"
            });
            enddate = item.enddate.replace(reg, function ($1, $2, $3) {
                return $2 + "年" + $3 + "月"
            });
            var $li = $('<li><span>' + begindate + ' - </span> <span>' + enddate + '</span><span style="margin-left: 5px"> ' + item.remark + ' </span></li>').appendTo($('#ul'))
            //$('#ul').append($li)
        });

        $.each(cur.experiences, function (i, item) {
            begindate = item.begindate.replace(reg, function ($1, $2, $3) {
                return $2 + "年" + $3 + "月"
            });
            enddate = item.enddate.replace(reg, function ($1, $2, $3) {
                return $2 + "年" + $3 + "月"
            });
            var $li = $('<li><span>' + begindate + ' - </span> <span>' + enddate + '</span><span style="margin-left: 5px"> ' + item.remark + ' </span></li>').appendTo( $('#J_workexp3'));
            //  $('#J_workexp3').append($li)
        });
        $photo.attr('src', cur.photo);
        $('#email').text(cur.email);
        $('#phone').text(cur.mobile);
        $('#zh').text(cur.ClassInNo);
        $('#subject').text(cur.educations);
        $('#introduce').text(cur.introduce);
        $('[name=tuid]').val(cur.teacheruid);
        $('#J_remark1').text(cur.remark1 || '');
        $('#J_remark2').text(cur.remark2 || '');
        $photo.attr('src', data.photo);
        $introduce.val(data.introduce);
        var src =$("#J_img").attr("src");
        if(src==''){
            $photo.hide()
        }else{
            $photo.show()
        }
    }
    $.ajax({
        url: ' /api/user/current',
        success: function (data) {
            doctorId = data.data.userid;
            $.ajax({
                url: '/api/teacher/user/' + doctorId,
                success: function (data) {
                    console.log(data)
                    teacheruid = data.data.teacheruid;
                    bind(data)
                }
            })
        }
    });


    $redact.click(function () {
        window.location.href = 'personSave.html';
    });
})



